package com.letchat.controller;

import com.letchat.pojo.Result;
import com.letchat.pojo.User;
import com.letchat.service.impl.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("users")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getUserById(@PathVariable Integer id) {
        return Result.success(userService.getUserById(id));
    }

    /**
     * 更新用户
     * @param user
     * @return
     */
    @PutMapping
    public Result updateUser(@RequestBody User user) {
        return Result.success(userService.updateUser(user));
    }
}
